package com.sharding.demo.config;


import org.apache.shardingsphere.infra.hint.HintManager;

/**
 * @Author hu xu hong
 * @Date 2023/2/2 17:28
 */
public class HintManagerUtils {
    /**
     * @Author shtdhr
     * @Description  Hint方式设置路由规则
     * @Date 2021/8/23 0023 下午 5:39
     * @Param  hintManager
     * @Param  TYPE 分片类型 DATABASE_TABLES 分库分表，DATABASE_ONLY 只分库
     * @Param  tableName 分片表（需要分表的表名）
     * @Param  value 分片值 orgNo (具体看自己需求)
     * @return
     */
    public static void setHintValue(final HintManager hintManager, HintType TYPE, String tableName, String value) {
        switch (TYPE) {
            case DATABASE_TABLES:
                hintManager.addDatabaseShardingValue(tableName, value);
                hintManager.addTableShardingValue(tableName, value);
                return;
            case DATABASE:
                hintManager.addDatabaseShardingValue(tableName, value);
                return;
            case TABLES:
                hintManager.addTableShardingValue(tableName, value);
                return;
            case DATABASE_ONLY:
                hintManager.setDatabaseShardingValue(value);
                return;
            default:
                throw new UnsupportedOperationException("unsupported type");
        }
    }
}
